/**
 * 向旧邮箱发送验证码
 */
function ajaxGetCodeToOldMail(that) {
    var url = "/Lvscore_User_M/account/ajaxGetCodeToOldMail";
    $.ajax({
            url:url,
            type:"post",
            //timeout:10000,
            success:function (data) {
                that.disabled = false;
                if (data == '1') {
                    alertBox("发送成功，请注意查收");
                } else if (data == '-1') {
                    validateSpanMsg("codeError","该邮箱已被注册");
                } else {
                    //validateSpanMsg("codeError","发送失败，服务器异常");
                    alertBox("发送失败，请重试", '');
                }
                settime(that);
            },
           error:function(){
               alertBox("网络异常，请重试","");
               //validateSpanMsg("codeError","网络异常，请重试");
               $("#get").val("获取验证码");
           },
           dataType: "json"
    });
}

/**
 * 验证旧邮箱验证码是否输入正确
 * code    用户输入的验证码
 */
function ajaxValidateCodeOldMail(code) {
    //loading("数据提交中...");
    var url = "/Lvscore_User_M/account/ajaxValidateCodeOldMail";
    $.post(
        url,
        {'code': code},
        function (data) {
            //$(".loadingBox").hide();
            if (data == 1) {
                window.location.href = "/Lvscore_User_M/userWeb/views/accounterCenter/newEmail.html?code=" + code;
            } else if(data==-1){
                validateSpanMsg("codeError","验证码错误");
            }else{
                alertBox("网络异常，请重试","");
            }
        },
        "json"
    );
}

$(function () {
    getUrl('accounterCenter/index','accounterCenter/changeEmail');
    $(".code").val("");
    var user = getUser_C();
    if (user) {
        $(".email").text(user.email);
    }
    //实时监控输入框
    inputChange(".code","#codeError");
    function codeMessage(){
        var code = $(".code").val();
        if (code == "" || code == null) {
            validateSpanMsg("codeError","请输入验证码");
            return false;
        }else{
            return true;
        }
    }
    $(".code").blur(function(){
        codeMessage();
    })
    $("#get").click(function () {
        $(this).disabled = true;
        $(this).val("发送中...");
        ajaxGetCodeToOldMail(this);
    })
    $(".sub").click(function () {
        var code = $(".code").val();
        if (codeMessage()){
            ajaxValidateCodeOldMail(code);
        }

    })
})